package com

import org.apache.flink.streaming.api.scala.{StreamExecutionEnvironment, _}
//flink run -c com.ReduceDriver -p 1 cq-flink-cdc-1.0-SNAPSHOT.jar
object ReduceDriver {
    def main(args: Array[String]): Unit = {
   val env=StreamExecutionEnvironment.getExecutionEnvironment
   
   val source =env.socketTextStream("192.168.249.100", 7777   )
//       val inputDataStream: DataStream[String] = env.socketTextStream("192.168.249.113", 7777)
 
  val result= source
//  .filter(line=>line.split(",")(1)=="M" ) 过滤
  .flatMap(line=> line.split(" "))
  .map(word=>(word,1))
    .keyBy(0) // 下标 表示按照单词在统计
   .sum(1) //sum 传下标 ，按照第几个元素求和 0 开始
   
   
   result.print()
   
   env.execute()
  } 
}